/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dal.TaiKhoanDAO;
import dto.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Stanley
 */
public class ModuleLoginLogoutController {

    private TaiKhoanDAO dao;

    public ModuleLoginLogoutController() {
        this.dao = new TaiKhoanDAO();
    }

    public ThiSinhDTO loginThiSinh(String cmnd) {
        ThiSinhDTO info = (ThiSinhDTO) dao.getThiSinh(cmnd);
        if (info != null) {
            if (info.getCmnd().equals(cmnd)) {
                return info;
            }
        }
        return null;
    }

    public QuanTriDTO loginQuanTri(String username, String password) {
        QuanTriDTO info = (QuanTriDTO) dao.getQuanTri(username, password);
        if (info != null) {
            if (info.getUsername().equals(username) && info.getPassword().equals(password)) {
                return info;
            }
        }
        return null;
    }

    public boolean signUpThiSinh(String hoten, String cmnd, String ngaysinh) {
        try {
            Date date = new SimpleDateFormat("yyyy-MM-dd").parse(ngaysinh);
            ThiSinhDTO info = new ThiSinhDTO(-1, cmnd, hoten, date);
            return dao.insertThiSinh(info);
        } catch (Exception e) {
            return false;
        }
    }
}
